package com.kingdee.eas.custom.hr.attendance.app;

import java.util.Date;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.eas.framework.report.util.RptParams;
import com.kingdee.eas.framework.report.util.RptRowSet;
import com.kingdee.eas.framework.report.util.SqlParams;

public class AttendanceRecordFacadeControllerBean extends
		AbstractAttendanceRecordFacadeControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.custom.hr.attendance.app.AttendanceRecordFacadeControllerBean");

	@Override
	protected RptParams _queryAttendanceRecord(Context ctx, RptParams params)
			throws BOSException {

		Date from = (Date) params.getObject("from");
		Date to = (Date) params.getObject("to");
		SqlParams parameters = new SqlParams();

		StringBuffer buffer = new StringBuffer();
		buffer.append("/*dialect*/SELECT A.FHITCARDDATE AS HITCARDDATE,	\n");
		buffer.append("A.FHITCARDTIME AS HITCARDTIME,			\n");
		buffer.append("A.FDOORNUM AS DOORNUM,					\n");
		buffer.append("A.FDOORNAME AS DOORNAME,					\n");
		buffer.append("A.FREMARK AS REMARK						\n");
		buffer.append("FROM CT_KQ_ATTENDANCERECORD A			\n");
		buffer.append(" WHERE A.FPERSONID=?						\n");
		parameters.addString(params.getString("person"));
		
		if (from != null) {
			buffer.append(" AND A.FHITCARDDATE>=?				\n");
			parameters.addDate(new java.sql.Date(from.getTime()));
		}

		if (to != null) {
			buffer.append(" AND A.FHITCARDDATE<=?				\n");
			parameters.addDate(new java.sql.Date(to.getTime()));
		}

		buffer.append("ORDER BY A.FHITCARDDATE ASC				\n");

		
		RptRowSet rs = this.executeQuery(buffer.toString(), parameters, ctx);

		params.setObject("record", rs);

		return params;
	}

	@Override
	protected RptParams _queryPerson(Context ctx, RptParams params)
			throws BOSException {
		StringBuffer buffer = new StringBuffer();
		buffer.append("/*dialect*/SELECT DISTINCT A.FPERSONID AS PERSON,	\n");
		buffer.append("B.FNUMBER AS PERSONNUM,					\n");
		buffer.append("B.FNAME_L2 AS PERSONNAME,				\n");
		buffer.append("E.FNAME_L2 AS ADMINORGUNIT,				\n");
		buffer.append("D.FNAME_L2 AS POSITION 					\n");
		buffer.append("  FROM CT_KQ_ATTENDANCERECORD A			\n");
		buffer.append("INNER JOIN T_BD_PERSON B ON A.FPERSONID = B.FID				 \n");
		buffer
				.append("INNER JOIN T_HR_PERSONPOSITION C ON B.FID=C.FPERSONID		 \n");
		buffer
				.append("INNER JOIN T_ORG_POSITION D ON C.FPRIMARYPOSITIONID=D.FID	 \n");
		buffer.append("INNER JOIN T_ORG_ADMIN E ON B.CFDEPTID=E.FID	 				 \n");
		buffer.append("WHERE "+ params.getString("where"));
		
		RptRowSet rs = this.executeQuery(buffer.toString(), null, ctx);
		params.setObject("result", rs);
		
		
		return params;
	}

}